package com.dkd.provider;

import com.dkd.interfaceinfo.domain.InterfaceInfo;
import com.dkd.interfaceinfo.domain.UserInterfaceInfo;
import com.dkd.interfaceinfo.mapper.UserInterfaceInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;


@DubboService
public class InerUserInterfaceInfoImpl implements InerUserInterfaceInfo{

    @Autowired
    private UserInterfaceInfoMapper userInterfaceInfoMapper;

    @Override
    public boolean invokeCount(long InterfaceInfoId, long userId) {
        if(InterfaceInfoId <= 0 || userId <= 0){
            throw new RuntimeException("参数错误");
        }
        boolean result = userInterfaceInfoMapper.updateUserInvokeCount(InterfaceInfoId, userId);
        return  result;
    }

    @Override
    public boolean IsInvoke(long InterfaceInfoId, long userId) {
        if(InterfaceInfoId <= 0 || userId <= 0){
            throw new RuntimeException("参数错误");
        }
        UserInterfaceInfo userInterfaceInfo = userInterfaceInfoMapper.IsInvoke(InterfaceInfoId, userId);
        if(userInterfaceInfo == null){
            return false;
        }
        if(userInterfaceInfo.getLeftNum() <= 0){
            return false;
        }
        return true;
    }
}
